package leetcode.method.dynamic_programming;

public class Program198RobTheHouse {

    public Program198RobTheHouse() {

    }

    public int rob(int[] nums) {
        int length = nums.length;
        if (length == 0) {
            return 0;
        }
        if (length == 1) {
            return nums[0];
        }

        int[][] dp = new int[length][2];
        dp[0][0] = 0;
        dp[0][1] = nums[0];
        for (int i = 1; i < length; i++) {
            dp[i][0] = Math.max(dp[i - 1][0], dp[i - 1][1]);
            dp[i][1] = dp[i - 1][0] + nums[i];
        }
        return Math.max(dp[length - 1][0], dp[length - 1][1]);
    }

    public static void main(String[] args) {
        Program198RobTheHouse myStack = new Program198RobTheHouse();
        int[] matrix = {1,2,3,1};
        System.out.println(myStack.rob(matrix));
        int[] matrix1 = {2,7,9,3,1};
        System.out.println(myStack.rob(matrix1));
    }
}
